<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/13
 * Time: 上午11:50
 */

namespace app\src\insurance\logic;


use app\src\base\logic\BaseLogic;
use app\src\insurance\model\Insurance;
use app\src\insurance\model\InsuranceOrderInfo;


class InsuranceOrderInfoLogic extends BaseLogic{



    public function _init()
    {
        $this->setModel(new InsuranceOrderInfo());
    }

    /*
     * 保险公司信息回传
     */
    public function addInfo($apply_id,$info){
        $apply=(new InsuranceApplyLogic())->getInfo(['id'=>$apply_id,'status'=>'0']);

        if(!empty($apply['info'])){
            $order=(new InsuranceOrderInfoLogic())->getInfo(['apply_id'=>$apply_id,'status'=>0]);

            $entity=[
                'apply_id'=>$apply_id,
                'order_id'=>'',
                'pay_img'=>'',
                'pay_info'=>json_encode($info, JSON_UNESCAPED_UNICODE),
                'order_status'=>'1',
                'create_time'=>NOW_TIME,
                'status'=>'0'
            ];

            if(!empty($order['info'])){

                $result = $this->save(['apply_id' => $apply_id],$entity);
                return $result;
            }else{
                $result=$this->add($entity,'');
                return $result;
            }

        }else{
            return(['status'=>false,'info'=>'没有该申请']);
        }

    }



}